package com.iamalive;

import java.util.List;


import com.iamalive.LocalCache.RecipientDetails;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.widget.AdapterView;
import android.view.View;
import android.widget.ArrayAdapter;


public class RecipientListActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		final StableArrayAdapter adapter = new StableArrayAdapter(this,
				android.R.layout.simple_list_item_1, LocalCache.getSingleInstance().getRecipientList());
		setListAdapter(adapter);
		
		getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, final View view,
					int position, long id) {
			   	//Toast.makeText(getApplicationContext(), "Click ListItem Number " + position, Toast.LENGTH_LONG).show();
				Intent i = new Intent(getApplicationContext(), UpdateRecipientActivity.class);
				String recipientName = (LocalCache.getSingleInstance().getRecipientNameList()).get(position);
				i.putExtra("Recipient Name", recipientName);
				startActivity(i);
			}
		});
	}

	private class StableArrayAdapter extends ArrayAdapter<RecipientDetails> {

	    //HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

	    public StableArrayAdapter(Context context, int textViewResourceId,
	        List<RecipientDetails> objects) {
	      super(context, textViewResourceId, objects);	      
	    }

/*	    @Override
	    public long getItemId(int position) {
	      InfoDetails infoDetails = getItem(position);
	      return mIdMap.get(item);
	    }

	    @Override
	    public boolean hasStableIds() {
	      return true;
	    }*/

	  }
	
//	private class StableArrayAdapter extends ArrayAdapter<String> {
//
//	    HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
//
//	    public StableArrayAdapter(Context context, int textViewResourceId,
//	        List<String> objects) {
//	      super(context, textViewResourceId, objects);
//	      for (int i = 0; i < objects.size(); ++i) {
//	        mIdMap.put(objects.get(i), i);
//	      }
//	    }
//
//	    @Override
//	    public long getItemId(int position) {
//	      String item = getItem(position);
//	      return mIdMap.get(item);
//	    }
//
//	    @Override
//	    public boolean hasStableIds() {
//	      return true;
//	    }
//
//	  }
	
	@Override
    protected void onResume() {
        super.onResume();

        //loginListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
        //loginList.setAdapter(loginListAdapter);  
        
		final StableArrayAdapter adapter = new StableArrayAdapter(this,
				android.R.layout.simple_list_item_1, LocalCache.getSingleInstance().getRecipientList());
		setListAdapter(adapter);
    }


}
